package main

import (
    "adkr/pkg/crypto"
    "flag"
    "log"
    "os"
    "path/filepath"
)

func main() {
    samplesDir := flag.String("samples", "pycompat_samples", "directory containing sample files")
    flag.Parse()
    
    s := crypto.NewSerializer()
    
    // List of sample files to verify
    sampleFiles := []string{
        "g1.bin", "g2.bin", "zr.bin", "gt.bin", 
        "list.bin", "tuple.bin", "map.bin",
    }
    
    log.Printf("Verifying Go serialization samples in %s", *samplesDir)
    
    for _, filename := range sampleFiles {
        filepath := filepath.Join(*samplesDir, filename)
        data, err := os.ReadFile(filepath)
        if err != nil {
            log.Fatalf("Failed to read %s: %v", filename, err)
        }
        
        // Try to deserialize the data
        obj, err := s.DeserializePyCompat(data)
        if err != nil {
            log.Fatalf("Failed to deserialize %s: %v", filename, err)
        }
        
        // Re-serialize to verify round-trip consistency
        data2, err := s.SerializePyCompat(obj)
        if err != nil {
            log.Fatalf("Failed to re-serialize %s: %v", filename, err)
        }
        
        // Check if round-trip is identical
        if len(data) != len(data2) {
            log.Printf("Warning: %s round-trip size mismatch: %d -> %d", filename, len(data), len(data2))
        } else {
            identical := true
            for i := 0; i < len(data); i++ {
                if data[i] != data2[i] {
                    identical = false
                    break
                }
            }
            if identical {
                log.Printf("✓ %s: %d bytes, round-trip identical", filename, len(data))
            } else {
                log.Printf("Warning: %s round-trip content differs", filename)
            }
        }
    }
    
    log.Printf("Verification completed successfully!")
}



